'This module was inspired by the VISUAL BASIC WORKSHOP column in the May 1994
'issue of Britain's PC PLUS magazine (pg 296), which introduced me to the joys
'of the BitBlt API call.
'
'To use the Dice, place the dice bitmap (dice.bmp) in a PictureBox on the
'form. You can hide it by pulling the side of the form over it (see
'Roller1.FRM) in the example. Place more PictureBoxes on the form, one for
'each of the die you want to show.
'
'Display the dice by calling the following subroutine:
'
'ShowDie (Source, Target, Digit, Color)
'
' where Source is the PictureBox containing the Dice Bitmap (dice.bmp)
' Target is the PictureBox that will contain the displayed die
' Digit is an integer between 1 and 6 referring to the die face
' Color is an integer between 1 and 3 referring to the die color
'
'
'To use the Numbers, place the Number bitmap (Num.bmp) in a PictureBox on
'the form. You can hide it by pulling the side of the form over it (see
'Roller1.FRM) in the example. place more PictureBoxes on the form, one for
'each Digit you want to show.
'
'Display the numbers by calling the following subroutine:
'
'ShowNum (Source, Target, Digit, Color)
'
' where Source is the PictureBox containing the Number Bitmap (num.bmp)
' Target is the PictureBox that will contain the displayed digit
' Digit is an integer between 0 and 9 referring to the value
' Color is an integer between 1 and 3 referring to the color
'
'
' Note: Make sure you set the AUTOREDRAW property of the hidden
' PictureBox(es) to TRUE or the graphics repaints won't work correctly.
'
Option Explicit
'Declare API call BitBlt
Global Const SRCCOPY = &HCC0020
Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer
Global res As Integer 'Holder for Funtion BitBlt result
Sub RollDice (DiePic As PictureBox, Color As Integer, Die1 As PictureBox, Die2 As PictureBox, Die3 As PictureBox, Die4 As PictureBox, Die5 As PictureBox)
'
'Rolls a set of 5 dice by randomly determining the result and
'calling Sub ShowDie
'
Dim A As Integer 'Holders for randomly generated numbvers
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Randomize 'get a random number between 1 and 6 for each
A = Int(6 * Rnd + 1) 'die
Randomize
B = Int(6 * Rnd + 1)
Randomize
C = Int(6 * Rnd + 1)
Randomize
D = Int(6 * Rnd + 1)
Randomize
E = Int(6 * Rnd + 1)
ShowDie DiePic, Die1, A, Color 'update the contents of each
ShowDie DiePic, Die2, B, Color 'die picture box
ShowDie DiePic, Die3, C, Color
ShowDie DiePic, Die4, D, Color
ShowDie DiePic, Die5, E, Color
End Sub
Sub RollNum (NumPic As PictureBox, Color As Integer, Num1 As PictureBox, Num2 As PictureBox, Num3 As PictureBox, Num4 As PictureBox, Num5 As PictureBox)
'
'Determines a set of 5 randomly determined numbers and displays them by
'calling Sub ShowDie
'
Dim A As Integer 'Holder for random number
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Randomize 'generate random numbers
A = Int(10 * Rnd + 1)
Randomize
B = Int(10 * Rnd + 1)
Randomize
C = Int(10 * Rnd + 1)
Randomize
D = Int(10 * Rnd + 1)
Randomize
E = Int(10 * Rnd + 1)
ShowNum NumPic, Num1, A, Color 'update contents of the five num
ShowNum NumPic, Num2, B, Color 'picture boxes
ShowNum NumPic, Num3, C, Color
ShowNum NumPic, Num4, D, Color
ShowNum NumPic, Num5, E, Color
End Sub
Sub ShowDie (Source As PictureBox, Target As PictureBox, Digit As Integer, Color As Integer)
'
'this subroutine clips a die face from the bitmap in SOURCE and
'puts it in TARGET
'PLEASE note that these two Parameters are reversed from Sub ShowNum because
'the two SOURCE bitmaps are oriented differently. That is, the dice bitmap
'is set up with the colors accross the top and the numbers down and the